package com.ternnetwork.configuration.controller.job;

import java.io.IOException;
import java.util.List;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;
import com.ternnetwork.commons.model.http.BaseResponse;
import com.ternnetwork.commons.utils.PackageClassesScaner;
import com.ternnetwork.configuration.entity.job.QuartzJob;
import com.ternnetwork.configuration.service.job.QuartzJobService;
import com.ternnetwork.configuration.ui.QuartzJobZtree;
import com.ternnetwork.annotation.QuartzJobImpl;



@Controller@Scope("prototype")
@RequestMapping("/configuration/job/*")
public class QuartzJobController {
	
	
	@Resource
	private QuartzJobService quartzJobService;
	

	
	@RequestMapping("manage.htm")
	public ModelAndView manage() throws IOException{
		String[] packagesToScan={"com.ternnetwork"};
		PackageClassesScaner  packageClassesScaner=new PackageClassesScaner(packagesToScan,QuartzJobImpl.class);
		return new ModelAndView("/WEB-INF/view/configuration/job/quartz_job_manage.jsp").addObject("jobClassList",packageClassesScaner.getClassesNameList());
	}
	
	
	
	@RequestMapping("add.htm")
	public @ResponseBody BaseResponse addQuartzJob(QuartzJob t){
	  return quartzJobService.idoAdd(t);
	}
	
	@RequestMapping("update.htm")
	public @ResponseBody BaseResponse updateQuartzJob(QuartzJob t) throws Exception{
		return quartzJobService.idoUpdate(t);
	}
	
	@RequestMapping("delete.htm")
	public @ResponseBody BaseResponse deleteQuartzJob(Long id) throws Exception{
	   return quartzJobService.idoDelete(id);
	}
	

	@RequestMapping("getZtreeJSON.htm")
	public @ResponseBody List<QuartzJobZtree> getQuartzZtreeJSON(HttpServletResponse response){
		 return quartzJobService.getZtreeList();
	}

}
